package com.sxz.sbs.module.message.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.message.mode.MessageBean;
import com.sxz.sbs.module.message.view.MessageView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;

/**
 * 消息list  P
 */

public class MessagePresenter extends RxPresenter<MessageView>{
    /**
     * 获取消息列表
     * @param map
     */
    public void getMessageList (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getMessageList(map)
                .compose(RxUtil.<MessageBean>handleResult())
                .subscribeWith(new RxSubscriber<MessageBean>(mView){
                    @Override
                    public void onNext(MessageBean token) {
                        mView.onGetMessageListSuccess(token);
                    }
                })
        );
    }
    /**
     * 处理消息
     * @param map
     */
    public void handleMessage (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().handleMessage(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String token) {
                        mView.onHandleMessageSuccess();
                    }
                })
        );
    }
}
